/*
 * @Author: sdorein sdorein@163.com
 * @Date: 2024-07-29 09:27:25
 * @LastEditors: sdorein sdorein@163.com
 * @LastEditTime: 2024-08-02 16:16:44
 * @FilePath: \vite-as-editor\src\permission.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
// src/plugins.ts
import type { App } from "vue";
import { defineAsyncComponent } from "vue";
import type { AsyncComponentLoader } from "vue"; // vue3+ts+vite 加上type,不然会报错。

// 样式初始化
import "css/reset.css";
import "css/minx.less";

// 引入字体图标
import "iconfont/iconfont.css";
import "iconfont/iconfont.js";

// 引入elementUI
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";

// 引入Vant
import Vant from "vant";
import "vant/lib/index.css";

// 引入请求拦截
//import '@/api/request';
// import httpApi from '@/api/api';

// 挂载 utils
//import Utils from './utils/index';

// 注册全局过滤器/时间戳转换日期
//import globalFilter from '@/utils/filter';

const components = import.meta.glob("./../components/**/*.vue"); //全局这个无论多少层级
/**
 * 全局组件引用管理
 */
export default {
  install(app: App) {
    console.log(app);
    app.use(ElementPlus);
    app.use(Vant);
    for (const [key, value] of Object.entries(components)) {
      const lastIndex = key.lastIndexOf("/");
      const secondLastIndex = key.lastIndexOf("/", lastIndex - 1);
      // 字符串截取，具体看下面console.log()中的name就知道了
      const name = key.slice(secondLastIndex + 1, lastIndex);
      if (key === "../components/componentscom/placementarea/index.vue") {
        console.log(name);
        console.log(value);
        console.log(defineAsyncComponent(value as AsyncComponentLoader));
        console.log(`注意这里的name名称=》》            ${name}       ===>这个名称，
      自己作为了全局祖册组件的名称了,也就是如左侧目录的：aaa.vue去掉.vue就剩下aaa了
      ，然后那这个名称作为组件引用的名称，具体看截图就知道了。这时就是相当于跟左侧
      项目目录的.vue结尾的文件去掉.vue得到的名称`);
      }
      app.component(name, defineAsyncComponent(value as AsyncComponentLoader));
    }
  },
};
